<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'vaga.label', default: 'Vaga')}" />
        <title><g:message code="default.edit.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="body">            
                <div class="cabelistlateral"><img src="${resource(dir:'images',file:'seta_cabecalho_20x20.png')}" /> Cadastro de Vagas</div><br/>
                <div class="dialog dadospessoais">
                  <g:if test="${flash.message}">
                      <div class="message">${flash.message}</div>
                  </g:if>
                  <g:hasErrors bean="${vagaInstance}">
                      <div class="errors erro">
                          <g:renderErrors bean="${vagaInstance}" as="list" />
                      </div>
                  </g:hasErrors>
                  <form method="post" action="${createLink(controller:'vaga', action:'update')}" >
                    <g:hiddenField name="id" value="${vagaInstance?.id}" />
                    <g:hiddenField name="version" value="${vagaInstance?.version}" />
                    <input type="hidden" name="unidadeConcedente.id" value="${vagaInstance?.unidadeConcedente.id}"/>
                    <input type="hidden" name="status" value="0"/>
                    <table>
                        <tbody>

                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="status"><g:message code="vaga.status.label" default="Status" /></label>
                                </td>
                                <%
                                String st    = "";
                                String style = "";
                                if(vagaInstance.status == "1"){
                                  st = "Ativo";
                                  style     = " style='color:#006600; font-weight:bold; font-size:14px;'";
                                }
                                if(vagaInstance.status == "0"){
                                  st = "Inativo";
                                  style     = " style='color:#ff0000; font-weight:bold; font-size:14px;'";
                                }
                                if(vagaInstance.dtFechamento){
                                  st = "Fechada";
                                  style     = " style='color:#000000; font-weight:bold; font-size:14px;'";
                                }
                                %>
                                <td<%=style%>>
                                    <%=st%>
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="cargo"><g:message code="vaga.cargo.label" default="Cargo" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'cargo', 'errors')}">
                                    <g:textField name="cargo" maxlength="200" value="${vagaInstance?.cargo}" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="atividade"><g:message code="vaga.atividade.label" default="Área de Atividade" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'atividade', 'errors')}">
                                    <g:select name="atividade.id" from="${Atividade.list()}" optionKey="id" value="${vagaInstance?.atividade?.id}" optionValue="descricao" noSelection="['':'Selecione']"/>
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="atribuicoes"><g:message code="vaga.atribuicoes.label" default="Atribuições" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'atribuicoes', 'errors')}">
                                    <g:textArea name="atribuicoes" cols="40" rows="5" value="${vagaInstance?.atribuicoes}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="perfil"><g:message code="vaga.perfil.label" default="Perfil" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'perfil', 'errors')}">
                                    <g:textArea name="perfil" cols="40" rows="5" value="${vagaInstance?.perfil}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="observacoes"><g:message code="vaga.observacoes.label" default="Observações" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'observacoes', 'errors')}">
                                    <g:textArea name="observacoes" cols="40" rows="5" value="${vagaInstance?.observacoes}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="remuneracao"><g:message code="vaga.remuneracao.label" default="Remuneração" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'remuneracao', 'errors')}">
                                    <g:textField name="remuneracao" value="${fieldValue(bean: vagaInstance, field: 'remuneracao')}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="qtdeVagas"><g:message code="vaga.qtdeVagas.label" default="Quantidade Vagas" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'qtdeVagas', 'errors')}">
                                    <g:textField name="qtdeVagas" value="${fieldValue(bean: vagaInstance, field: 'qtdeVagas')}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="chSemanal"><g:message code="vaga.chSemanal.label" default="Carga Horária Semanal" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'chSemanal', 'errors')}">
                                    <g:textField name="chSemanal" value="${fieldValue(bean: vagaInstance, field: 'chSemanal')}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="dtFechamento"><g:message code="vaga.dtFechamento.label" default="Data Fechamento" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'dtFechamento', 'errors')}">
                                    <g:datePicker name="dtFechamento" precision="day" value="${vagaInstance?.dtFechamento}" default="none" noSelection="['': '']" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="motivoFecha"><g:message code="vaga.motivoFecha.label" default="Motivo Fechamento" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'motivoFecha', 'errors')}">
                                    <g:textField name="motivoFecha" maxlength="45" value="${vagaInstance?.motivoFecha}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="justificativaFecha"><g:message code="vaga.justificativaFecha.label" default="Justificativa Fechamento" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: vagaInstance, field: 'justificativaFecha', 'errors')}">
                                    <g:textField name="justificativaFecha" value="${vagaInstance?.justificativaFecha}" />
                                </td>
                            </tr>
                            <tr>
                              <td></td>
                              <td class="btsalvarcadastro">
                                  <g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}"/>
                                  <sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_ATENDENTE">
                                      <%
                                      if(vagaInstance.status == "0"){
                                          %>
                                          <input type="button" value="ATIVAR" onclick="location.href='${createLink(controller:'vaga', action:'ativarVaga', id:vagaInstance?.id, params:[status:1])}';" />
                                          <%
                                      }else{
                                          %>
                                          <input type="button" value="DESATIVAR" onclick="location.href='${createLink(controller:'vaga', action:'desativarVaga', id:vagaInstance?.id, params:[status:0])}';" />
                                          <%
                                      }
                                      %>
                                      <input type="button" value="VOLTAR" onclick="location.href='${createLink(controller:'vaga', action:'listaVagasInativas')}';" />    
                                  </sec:ifAnyGranted>
                                  <sec:ifAnyGranted roles="ROLE_UC">
                                    <input type="button" value="VOLTAR" onclick="location.href='${createLink(controller:'vaga', action:'list')}';" />
                                    <input type="button" value="NOVO" onclick="location.href='${createLink(controller:'vaga', action:'create')}';"/>
                                  </sec:ifAnyGranted>
                              </td>
                            </tr>
                        </tbody>
                    </table>
                    </form>
                </div>

                <sec:ifAnyGranted roles="ROLE_UC">
                    <div class="dadoslateral">
                          <div class="contatos">
                          <h1 class="cabelistlateral">Cursos</h1>
                          <g:hasErrors bean="${cursoInstance}">
                          <div class="errors">
                              <g:renderErrors bean="${cursoInstance}" as="list" />
                          </div>
                          </g:hasErrors>
                          <form method="post" action="/EstagioWeb/vaga/saveCurso">
                              <input type="hidden" name="vaga.id" value="${vagaInstance.id}"/>
                              <div class="dialog">
                                  <table>
                                      <tbody>
                                          <tr class="prop cadastrolateral">
                                              <td valign="top" class="name" class="value ${hasErrors(bean: cursoInstance, field: 'descricao', 'errors')}">
                                                  <label for="descricao"><g:message code="curso.descricao.label" default="Curso" /></label>
                                                  <br/>
                                                  <select name="curso.id" style="width:310px;">
                                                      <option value="">Selecione</option>
                                                      <%
                                                      if(cursoInstance){
                                                        for(int i=0; i<cursoInstance.size();i++){
                                                            %>
                                                            <option value="<%=cursoInstance.id[i]%>"><%=cursoInstance.descricao[i]%></option>
                                                            <%
                                                        }
                                                      }
                                                      %>
                                                  </select>
                                              </td>
                                              <td class="btsalvarlateral">
                                                  <g:submitButton name="create" class="save ui-corner-all" value="SALVAR" />
                                              </td>
                                          </tr>
                                      </tbody>
                                  </table>
                              </div>
                          </form>
                          </div>
                          <%
                          if(cursoInstanceList){
                              %>
                              <div class="list">
                                  <table>
                                      <thead>
                                          <tr>
                                              <g:sortableColumn property="curso" title="${message(code: 'curso.descricao.label', default: 'Curso')}" />
                                              <td class="acao">Ações</td>
                                          </tr>
                                      </thead>
                                      <tbody>
                                      <g:each in="${cursoInstanceList}" status="i" var="cursoInstance">
                                          <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                                              <td>${fieldValue(bean: cursoInstance, field: "descricao")}</td>
                                              <td class="ico">
                                                  <a href="${createLink(uri: '/vaga/deleteCurso?idc='+cursoInstance.id+'&idv='+vagaInstance.id)}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Confirma aexclusão do registro?')}');">
                                                      <img src="${resource(dir:'images',file:'ico_delete.png')}" alt="Excluir Item" title="Excluir Item" class="formacao" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}"  />
                                                  </a>
                                              </td>
                                          </tr>
                                      </g:each>
                                      </tbody>
                                  </table>
                              </div>
                              <div class="paginateButtons">
                                  <g:paginate total="${cursoInstanceTotal}" />
                              </div>
                              <%
                          }
                          %>
                    </div>
                </sec:ifAnyGranted>
                <sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_ATENDENTE">
                    <div class="dadoslateral">
                        <div class="contatos">
                        <h1 class="cabelistlateral">Cursos</h1>
                        <%
                        if(cursoInstanceList){
                            %>
                            <div class="list">
                                <ul>
                                  <g:each in="${cursoInstanceList}" status="i" var="cursoInstance">
                                    <li>${fieldValue(bean: cursoInstance, field: "descricao")}</li>
                                  </g:each>
                                </ul>
                            </div>
                            <%
                        }else{
                            %>
                            <div class="list">Nenhum há cursos.</div>
                            <%
                        }
                        %>
                        </div>
                    </div>
                </sec:ifAnyGranted>

                <sec:ifAnyGranted roles="ROLE_UC">
                    <div class="dadoslateral">
                          <div class="contatos">
                          <h1 class="cabelistlateral">Benefícios</h1>
                          <g:hasErrors bean="${beneficioInstance}">
                          <div class="errors">
                              <g:renderErrors bean="${beneficioInstance}" as="list" />
                          </div>
                          </g:hasErrors>
                          <form method="post" action="/EstagioWeb/vaga/saveBeneficio">
                              <input type="hidden" name="vaga.id" value="${vagaInstance.id}"/>
                              <div class="dialog">
                                  <table>
                                      <tbody>
                                          <tr class="prop cadastrolateral">
                                              <td valign="top" class="name" class="value ${hasErrors(bean: beneficioInstance, field: 'descricao', 'errors')}">
                                                  <label for="descricao"><g:message code="beneficio.descricao.label" default="Beneficio" /></label>
                                                  <br/>
                                                  <select name="beneficio.id" style="width:310px;">
                                                      <option value="">Selecione</option>
                                                      <%
                                                      if(beneficioInstance){
                                                        for(int i=0; i<beneficioInstance.size();i++){
                                                            %>
                                                            <option value="<%=beneficioInstance.id[i]%>"><%=beneficioInstance.descricao[i]%></option>
                                                            <%
                                                        }
                                                      }
                                                      %>
                                                  </select>
                                              </td>
                                              <td class="btsalvarlateral">
                                                <g:submitButton name="create" class="save ui-corner-all" value="SALVAR" />
                                              </td>
                                          </tr>
                                      </tbody>
                                  </table>
                              </div>
                          </form>
                          </div>
                          <%
                          if(beneficioInstanceList){
                              %>
                              <div class="list">
                                  <table>
                                      <thead>
                                          <tr>
                                              <g:sortableColumn property="beneficio" title="${message(code: 'beneficio.descricao.label', default: 'Beneficio')}" />
                                              <td class="acao">Ações</td>
                                          </tr>
                                      </thead>
                                      <tbody>
                                      <g:each in="${beneficioInstanceList}" status="i" var="beneficioInstance">
                                          <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                                              <td>${fieldValue(bean: beneficioInstance, field: "descricao")}</td>
                                              <td class="ico">
                                                  <a href="${createLink(uri: '/vaga/deleteBeneficio?idb='+beneficioInstance.id+'&idv='+vagaInstance.id)}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Confirma aexclusão do registro?')}');">
                                                      <img src="${resource(dir:'images',file:'ico_delete.png')}" alt="Excluir Item" title="Excluir Item" class="formacao" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}"  />
                                                  </a>
                                              </td>
                                          </tr>
                                      </g:each>
                                      </tbody>
                                  </table>
                              </div>
                              <div class="paginateButtons">
                                  <g:paginate total="${beneficioInstanceTotal}" />
                              </div>
                              <%
                          }
                          %>
                    </div>
                </sec:ifAnyGranted>
                <sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_ATENDENTE">
                    <div class="dadoslateral">
                        <div class="contatos">
                            <h1 class="cabelistlateral">Benefícios</h1>
                            <%
                            if(beneficioInstanceList){
                                %>
                                <div class="list">
                                    <ul>
                                    <g:each in="${beneficioInstanceList}" status="i" var="beneficioInstance">
                                      <li>${fieldValue(bean: beneficioInstance, field: "descricao")}</li>
                                    </g:each>
                                    </ul>
                                </div>
                                <%
                            }else{
                                %>
                                <div class="list">Nenhum há beneficios.</div>
                                <%
                            }
                            %>
                        </div>
                    </div>
                </sec:ifAnyGranted>

                <sec:ifAnyGranted roles="ROLE_UC">
                    <div class="dadoslateral">
                          <div class="contatos">
                          <h1 class="cabelistlateral">Curriculos Enviados</h1>
                          <%
                          if(envioVagaInstanceList){
                              %>
                              <div class="list">
                                  <table class="enviovaga">
                                      <tbody>
                                          <thead>
                                              <tr>
                                                  <g:sortableColumn class="dtenvio" property="dtEnvio" title="${message(code: 'envioVaga.dtEnvio.label', default: 'Data')}" />
                                                  <g:sortableColumn class="nome" property="nome" title="${message(code: 'estagiario.nome.label', default: 'Nome')}" />
                                                  <td colspan="2">Ações</td>
                                              </tr>
                                          </thead>
                                          <g:each in="${envioVagaInstanceList}" status="i" var="envioVagaInstance">
                                              <tr>
                                                  <%
                                                  def solicitacaoInstance = Solicitacao.findByEstagiarioAndVaga(Estagiario.get(envioVagaInstance.estagiario.id), Vaga.get(envioVagaInstance.vaga.id));
                                                  %>
                                                <td><g:formatDate date="${envioVagaInstance?.dtEnvio}" format="dd-MM-yyyy"/></td>
                                                <td>${envioVagaInstance?.estagiario?.nome}</td>
                                              
                                                  <td class="btsalvarcadastro">
                                                      <input type="button" name="curriculo" value="CURRICULO" onclick="window.open('${createLink(controller:'estagiario', action:'show', id:envioVagaInstance.estagiario.id)}');"/>
                                                      <%
                                                      // verifica se ja existe solicitação.
                                                      if(!Solicitacao.findByEstagiarioAndVaga(Estagiario.get(envioVagaInstance.estagiario.id), Vaga.get(envioVagaInstance.vaga.id))){
                                                          %>
                                                          <input type="button" name="gerar" value="GERAR SOLICITAÇÃO" onclick="location.href='${createLink(controller:'solicitacao', action:'gerarSolicitacao', id:envioVagaInstance.id)}';"/>
                                                          <%
                                                      }else{
                                                          %>
                                                          <input type="button" name="gerar" value="EXCLUIR SOLICITAÇÃO" onclick="location.href='${createLink(controller:'solicitacao', action:'excluirSolicitacao', id:solicitacaoInstance.id, params:[controlador:'vaga', acao:'edit'])}';"/>
                                                          <%
                                                      }
                                                      %>
                                                  </td>
                                              </tr>
                                          </g:each>
                                      </tbody>
                                  </table>
                              </div>
                              <%
                          }else{
                              %>
                              <div class="list">Nenhum curriculo enviado.</div>
                              <%
                          }
                          %>
                    </div>
                </div>
             </sec:ifAnyGranted>
             <sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_ATENDENTE">
                <div class="dadoslateral">
                    <div class="contatos">
                        <h1 class="cabelistlateral">Curriculos Enviados</h1>
                        <%
                        if(enviaVagaInstanceList){
                            %>
                            <div class="list">
                                <ul>
                                <g:each in="${enviaVagaInstanceList}" status="i" var="enviaVagaInstance">
                                    <%
                                    def estagiarioInstance = Estagiario.findById(envioVagaInstance.estagiario.id);
                                    %>
                                    <li>${fieldValue(bean: estagiarioInstance, field: "dtEnvio")} -> ${fieldValue(bean: estagiarioInstance, field: "nome")}</li>
                                </g:each>
                                </ul>
                            </div>
                            <%
                        }else{
                            %>
                            <div class="list">Nenhum curriculo enviado.</div>
                            <%
                        }
                        %>
                    </div>
                </div>
            </sec:ifAnyGranted>
        </div>
    </body>
</html>
